
* replicates all figures and tables in the main text of the article

clear *

* define programs to be used
* setup
program define setup
	use survey, clear
	do "-controls.do"
end

* get coefficients, standard errors and p-values
program define getcoef
	args x j /* x = variable, j = number of matrix */
	reg `x' i.t15 $controls1, r
	mat obs`j' = e(N)
	* all coefficients and SEs
	mat coef`j' = e(b)
	mat var`j' = vecdiag(e(V))
	matmap var`j' se`j', m(sqrt(@))
	mat pval`j' = r(table)
	local C = colsof(pval`j')
	mat pval`j' = pval`j'[4..4,1..`C']
	mat coef`j' = coef`j'', se`j'',pval`j''
	* only class variables for text
	mat coef`j' = coef`j'[2..4,1..3]
	* predicted value for general population
	margins, at(t15 = 1) post
	mat pred`j' = (_b[_cons],_se[_cons],.)
	mat coef`j' = coef`j' \ pred`j'
end

* merge all appropriate models into one table
program define coefmerge
	args m n /* m = matrix name, n = number of columns */
	mat `m' = `m'1
	forval i = 2/`n' {
		mat `m' = `m',`m'`i'
		}
end

* shortened table for main text
program define tables
	frmttable, clear
	frmttable, statmat(coef) substat(2) sdec(2) ///
		rtitles("Highly affluent (top 1\%)" \ "" \ "" \ "Affluent (95-99\%)" \ "" \ "" \ ///
		"Upper middle class ($\sim$80-95\%)" \ "" \ "" \ "General population" \ "---predicted value" \ "")
	frmttable, statmat(obs) substat(0) sdec(0) rtitle("N") append
end

* capture both 95 and 90 CIs for graphs
program def ci9590
	args m /* number of attribution vars */
	$cond
	forval i = 1/`m' {
		mat `: word `i' of ${vars}' = J(3,1,.)
		mat `: word `i' of ${vars}'95 = J(3,2,.)
		mat `: word `i' of ${vars}'90 = J(3,2,.)
		}
	forval i = 1/`m' {
		qui reg policy ($vars1)##i.t15r $controls1 $add $weight, r
		qui margins, dydx(`: word `i' of ${vars}') at(t15r = (1 2 3)) post
		mat `: word `i' of ${vars}' = e(b)'
		foreach l in 95 90 {
			qui reg policy ($vars1)##i.t15r $controls1 $add $weight, r
			qui margins, dydx(`: word `i' of ${vars}') at(t15r = (1 2 3)) l(`l') post
			mat `: word `i' of ${vars}'`l' = r(table)'
			mat `: word `i' of ${vars}'`l' = `: word `i' of ${vars}'`l'[1..3,5..6]
			}
		}
	clear 
	forval i = 1/`m' {
		svmat `: word `i' of ${vars}'
		foreach l in 95 90 {
			svmat `: word `i' of ${vars}'`l'
			}
		}
end

/*--------------------------------------------------------------------------*/
/* Figure 1: Sample breakdowns by income and gross financial assets */
/*--------------------------------------------------------------------------*/

use survey, clear

replace incomebin2 = 0 if incomebin2 == .
lab def incomebin2 0 "N/A", modify
lab val incomebin2 incomebin2
replace assetsall = 0 if assetsall == .
lab def assets1 0 "N/A" 1 "<$250K" 2 "$250-500K" 3 "$500-750K" 4 "$750-1M" 5 "$1-2M" 6 "$2-5M" ///
	7 "$5-10M" 8 "$10-25M" 9 "$25-50M" 10 ">$50M", replace
lab val assetsall assets1
gen one = 1

preserve
collapse (count) one if wealthy == 0, by(incomebin2)
twoway (bar one incomebin2, fcolor(gs10) lcolor(gs9)), ///
	scheme(s1mono) xlabel(0(1)10, valuel angle(45) format(%9.0f) noticks labgap(1.8)) ///
	legend(off) xtitle("") ytitle("Frequency")  title("General population sample") ///
	aspect(.7) name(income_gp, replace) nodraw
restore, preserve
collapse (count) one if wealthy == 1, by(incomebin2)
twoway (bar one incomebin2, fcolor(gs10) lcolor(gs9)), ///
	scheme(s1mono) xlabel(0(1)10, valuel angle(45) format(%9.0f) noticks labgap(1.8)) ///
	legend(off) xtitle("") ytitle("Frequency")  title("Affluent sample") ///
	aspect(.7) name(income_w, replace) nodraw
restore

preserve
collapse (count) one if wealthy == 0, by(assetsall)
twoway (bar one assetsall, fcolor(gs10) lcolor(gs9)), ///
	scheme(s1mono) xlabel(0(1)10, valuel angle(45) format(%9.0f) noticks labgap(1.8)) ///
	legend(off) xtitle("") ytitle("Frequency")  title("General population sample") ///
	aspect(.7) name(assets_gp, replace) nodraw
restore, preserve
collapse (count) one if wealthy == 1, by(assetsall)
twoway (bar one assetsall, fcolor(gs10) lcolor(gs9)), ///
	scheme(s1mono) xlabel(0(1)10, valuel angle(45) format(%9.0f) noticks labgap(1.8)) ///
	legend(off) xtitle("") ytitle("Frequency")  title("Affluent sample") ///
	aspect(.7) name(assets_w, replace) nodraw

gr combine income_gp income_w, scheme(s1mono) title("Household income") ///
	name(income, replace) ysize(3) xsize(6) ycommon nodraw
gr combine assets_gp assets_w, scheme(s1mono) title("Gross financial assets") ///
	name(assets, replace) ysize(3) xsize(6) ycommon nodraw
gr combine income assets, scheme(s1mono) rows(2) scale(.92) ysize(6) xsize(6)

/*--------------------------------------------------------------------------*/
/* Table 1: Affluence and first-order attributions */
/*--------------------------------------------------------------------------*/

setup
local k = 1
foreach y in disp sit foa_diff {
	getcoef `y' `k'
	local k = `k' + 1
	}
foreach a in coef obs {
	coefmerge `a' 3
	}
tables

/*--------------------------------------------------------------------------*/
/* Table 2: Affluence and second-order attributions */
/*--------------------------------------------------------------------------*/

setup
local k = 1
foreach y in choice genes envir dd {
		getcoef `y' `k'
		local k = `k' + 1
		}
foreach a in coef obs {
	coefmerge `a' 4
	}
tables

/*--------------------------------------------------------------------------*/
/* Table 3: Affluence and political attitudes */
/*--------------------------------------------------------------------------*/

setup
local k = 1
foreach y in ineq govt taxes policy {
	getcoef `y' `k'
	local k = `k' + 1
	}
foreach a in coef obs {
	coefmerge `a' 4
	}
tables

/*--------------------------------------------------------------------------*/
/* Figure 2: Affluence, first-order attributions, and political attitudes */
/*--------------------------------------------------------------------------*/

setup
global vars disp sit
global vars1 c.disp c.sit
ci9590 2
gen n = _n
twoway (rcap disp951 disp952 n, msize(0) lcol(black) lwidth(vthin) horizontal) ///
	(rcap disp901 disp902 n, msize(0) lcol(black) lwidth(medthick) horizontal) ///
	(scatter n disp1, mcol(black) msize(large) msymbol(O)), ///
	aspect(1.3) xline(0, lpattern(dot) lcolor(gs8) lwidth(medthick)) ///
	legend(off) xtitle("") title("Dispositional") ytitle("") ///
	ylab(1 `""General" "population""' 2 `""Upper middle" " class (~80-95%)""' 3 "Top 5%", angle(0)) ///
	scheme(s1mono) yscale(range(.5(.5)3.5)) ///
	xscale(range(-.6(.2).2)) xlabel(#5) name(disp, replace) nodraw
twoway (rcap sit951 sit952 n, msize(0) lcol(black) lwidth(vthin) horizontal) ///
	(rcap sit901 sit902 n, msize(0) lcol(black) lwidth(medthick) horizontal) ///
	(scatter n sit1, mcol(black) msize(large) msymbol(O)), ///
	aspect(1.3) ///
	legend(off) xtitle("") title("Situational") ytitle("") ///
	ylab(1 `""General" "population""' 2 `""Upper middle" " class (~80-95%)""' 3 "Top 5%", angle(0)) ///
	scheme(s1mono) yscale(range(.5(.5)3.5) alt) ///
	xscale(range(0.2(.2)1)) xlabel(#5) name(sit, replace) nodraw
gr combine disp sit, rows(1) scheme(s1mono) ///
	b1("Association between one-unit increase" "in attribution and economic liberalism", size(small)) ///
	ysize(3) scale(1.35)

/*--------------------------------------------------------------------------*/
/* Figure 3: Affluence, second-order attributions, and political attitudes */
/*--------------------------------------------------------------------------*/

setup
global vars choice genes envir
global vars1 c.choice c.genes c.envir
ci9590 3
gen n = _n
twoway (rcap choice951 choice952 n, msize(0) lcol(black) lwidth(vthin) horizontal) ///
	(rcap choice901 choice902 n, msize(0) lcol(black) lwidth(medthick) horizontal) ///
	(scatter n choice1, mcol(black) msize(large) msymbol(O)), ///
	xline(0, lpattern(dot) lcolor(gs8) lwidth(medthick)) ///
	legend(off) xtitle("") title("Choice") ytitle("") ///
	ylab(1 `""General" "population""' 2 `""Upper middle" " class (~80-95%)""' 3 "Top 5%", angle(0)) ///
	scheme(s1mono) yscale(range(.5(.5)3.5)) ///
	xscale(range(-.6(.2).2)) xlabel(#5) name(choice, replace) nodraw
twoway (rcap genes951 genes952 n, msize(0) lcol(black) lwidth(vthin) horizontal) ///
	(rcap genes901 genes902 n, msize(0) lcol(black) lwidth(medthick) horizontal) ///
	(scatter n genes1, mcol(black) msize(large) msymbol(O)), ///
	xline(0, lpattern(dot) lcolor(gs8) lwidth(medthick)) ///
	legend(off) xtitle("") title("Genes") ytitle("") ///
	ylab(, nolabel noticks) fxsize(35.5) xscale(range(-.4(.2).4)) xlabel(#5) ///
	scheme(s1mono) yscale(range(.5(.5)3.5) alt) name(genes, replace) nodraw
twoway (rcap envir951 envir952 n, msize(0) lcol(black) lwidth(vthin) horizontal) ///
	(rcap envir901 envir902 n, msize(0) lcol(black) lwidth(medthick) horizontal) ///
	(scatter n envir1, mcol(black) msize(large) msymbol(O)), ///
	xline(0, lpattern(dot) lcolor(gs8) lwidth(medthick)) ///
	legend(off) xtitle("") title("Environment") ytitle("") ///
	ylab(1 `""General" "population""' 2 `""Upper middle" " class (~80-95%)""' 3 "Top 5%", angle(0)) ///
	scheme(s1mono) yscale(range(.5(.5)3.5) alt) ///
	xscale(range(-.4(.2).4)) xlabel(#5) name(envir, replace) nodraw
gr combine choice genes envir, rows(1) scheme(s1mono) ///
	b1("Association between one-unit increase" "in attribution and economic liberalism", size(small)) ///
	scale(1.2) xsize(8) ysize(4.35)

gr drop _all
